package com.android.pagemarket.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

import com.android.pagemarket.R;
import com.android.pagemarket.business.model.Paper.Price;
import com.android.pagemarket.ui.activity.base.BaseActivity;
import com.android.pagemarket.ui.activity.price.MaterialDetailActivity;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-11-8
 * @see : 报价表格的视图
 * @Copyright : copyrights reserved by personal 2007-2011
 **********************************************************/
public class QuotItemView extends TableRow implements android.view.View.OnClickListener
{

    private TextView paper;
    private TextView price;
    private Price    mData;
    
    public QuotItemView(Context context)
    {
        this(context,null);
    }
    
    public QuotItemView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }
    
    @Override
    protected void onFinishInflate()
    {
        super.onFinishInflate();
        
        paper = (TextView)findViewById(R.id.paper);
        price = (TextView)findViewById(R.id.price);
    }

    public QuotItemView bindData(Price data, int position)
    {
        mData = data;
        paper.setText(mData.paper);
        price.setText(mData.price+"");
        setBackgroundResource( position %2 == 0 ? R.drawable.bg_paper_item_0 : R.drawable.bg_paper_item_1);
        setOnClickListener(this);
        return this;
    }

    @Override
    public void onClick(View v)
    {
        if(mData.brandList == null || mData.brandList.size() == 0)
        {
            Toast.makeText(getContext(), "该纸质没有详情！", Toast.LENGTH_SHORT).show();
            return;
        }
        // 查看
        MaterialDetailActivity.startActivity(getContext(), mData);
    }
}
